<template>
    <div class="for-cover amusing">
        <no-data v-if="storeMsg && Object.keys(storeMsg).length > 0 && storeMsg.list && storeMsg.list.length == 0">
        </no-data>
        <full-img-video-swiper ref="fullImgVideoSwiper"
            v-else-if="storeMsg && Object.keys(storeMsg).length > 0 && storeMsg.list && storeMsg.list.length > 0"
            :swiperContentProp="dealStoreMsg(storeMsg)" :discountList="discountList"
            :commentListProps="commentListProps" :couponsListProp="couponsList" :rtCommontListProps="shareCollectSpeak"
            @showShare="showShare = true" @clickHeaderImg="toStoreHome" @doAttention="doAttention"
            @getPageMsg="getPageMsg" @suspensionCb="suspensionCb" @getAllCounponsFn="getAllCounponsFn"
            @getTemplate="getTemplate" @isShowHomeTap="isShowHomeTap" @openRedPage="openRedPage"
            @animationCb="animationCb" @doAppraise="doAppraise" @initAppraiseHelp="initAppraiseHelp" @isLike="isLike"
            @doComment="doComment" @getSubCommentList="getSubCommentList" @getUserMainComment="getUserMainComment">
        </full-img-video-swiper>
        <v-share v-if="showShare" @clickFn="showShare = false"></v-share>
    </div>
</template>

<script>
import XLocation from "../../x/XLocation";
import FullImgVideoSwiper from "../../components/commonActModel/panoramaVideoSwiper/FullImgVideoSwiper";
import {mapGetters} from 'vuex';
export default {
    name: "NewAmusing",
    props: {
        propsPage: {
            type: Object
        }
    },
    data () {
        return {
            storeMsg: {},
            suspension: true,
            discountList: [],//优惠券列表
            couponsList: [],
            shareCollectSpeak: [],
            commentListProps: { userHendleType: 'module5' },//评论弹出框的数据
            showShare: false,//分享的弹框
            distanceIndex: 0,//距离index
            pageNum: 1,//好玩拉取的当前页面
            giveChannel: 0,//好玩页面0，商家页面1
            pageSize: 10,//一次性拉取的好玩页面的数据条数
            shareBody: {},//分享
            commentType: 0,
            commentKey: 0,
            commentPageNum: 1,
            commentPageSize: 5,
            interact: {
                appraise: {},//估价活动
            },//互动
        }
    },
    created () {
    },
    computed: {
        ...mapGetters({
            currentUserStoreDiscount: 'currentUserStoreDiscountFn',
            currentStore: 'currentStoreFn',
            currentUser: 'currentUserFn',
            currentThird: 'currentThirdFn',
        }),
    },
    mounted () {
        let that = this;
        if (that.propsPage) {
            let keys = Object.keys(that.propsPage);
            if (this.propsPage && keys.includes("bottomDownShow")) {
                this.bottomDownShow = this.propsPage.bottomDownShow;
            }
        }
        this.init();
    },
    methods: {
        init () {
            this.getPageMsg();
        },
        getPageMsg () {
            let that = this;
            let data = {
                "pageNum": that.pageNum,
                "pageSize": that.pageSize,
            };
            let headPromotionId = '';
            if (this.$route.query && this.$route.query.shareId) {
                headPromotionId = `?headPromotionId=${this.$route.query.shareId}`
            }
            let params = {
                data,
                headPromotionId,
                userId: this.userId,
            }
            this.$store.dispatch('getPageMsgApi', params).then((data) => {
                if (data.success) {
                    this.storeMsg = data;
                    that.dealShareCollectSpeak(data)
                    // this.getUserMainComment(this.storeMsg);
                    for (let value in that.storeMsg.list) {
                        that.couponsRedDeal(that.storeMsg.list[value], value);
                        that.countDistance(that.storeMsg.list[value]);
                    }
                    /*评论区*/
                } else if (data.errMsg) {
                    this.$root.$emit("toast", { msg: data.errMsg })
                } else {
                    this.$root.$emit("toast", { msg: '获取页面信息出错' })
                }
            })
        },
        toStoreHome (obj) {
            let storeId = obj.storeId;
            let promotionId = obj.promotionId;
            this.$router.push({ path: '/store', query: { storeId: storeId, promotionId: promotionId } });
        },
        /*距离*/
        countDistance (storeMsg) {
            let that = this;
            let belongStoreInfo = storeMsg.belongStoreInfo
            if (belongStoreInfo.storeId && belongStoreInfo.latitude && belongStoreInfo.longitude) {
                this.distanceIndex++;
                // let tempLocation = XLocation.getLocationDiscount({
                //     latitude: belongStoreInfo.latitude,
                //     longitude: belongStoreInfo.longitude
                // });
                // tempLocation.then((data) => {
                //     let tempObj = {
                //         storeId: belongStoreInfo.storeId,
                //         discount: data,
                //     };
                //     that.discountList.push(tempObj);
                // });
                let tempObj = {
                    storeId: belongStoreInfo.storeId,
                    discount: this.currentUserStoreDiscount,
                };
                that.discountList.push(tempObj);
            }
        },
        openRedPage (obj, callback) {
            let that = this;
            if (!this.userId) {
                this.$router.push('/to/login');
                return
            }
            let url = "";
            /*普通红包*/
            if (obj && obj.welPacketType == 0) {
                url = `${this.NW_API_API_LOCALE_VERSION}/welfare/direct/packet/receive?userId=${this.userId}&giveChannel=${this.giveChannel}&welPacketId=${obj.welPacketId}`;
                /*助力红包*/
            } else if (obj && obj.welPacketType == 1) {
                url = `${this.NW_API_API_LOCALE_VERSION}/welfare/help/packet/receive?userId=${this.userId}&welPacketId=${obj.welPacketId}`
                /*成长红包*/
            } else if (obj && obj.welPacketType == 2) {
                url = `${this.NW_API_API_LOCALE_VERSION}/welfare/grow/packet/receive?userId=${this.userId}&welPacketId=${obj.welPacketId}`
            }
            this.xurl.put(url).then((data) => {
                if (data.success) {
                    for (let value in that.couponsList) {
                        if (that.couponsList[value].couponsProps.myPacketInfo && obj.welPacketId == that.couponsList[value].couponsProps.myPacketInfo.welPacketId) {
                            that.couponsList[value].couponsProps.myPacketInfo.canReceive = false;
                            that.couponsList[value].couponsProps.myPacketInfo.showReceivedAmount = true;
                            that.couponsList[value].couponsProps.myPacketInfo.receivedAmount = data.result;
                            that.couponsList[value].couponsProps.getBtnActive = false;
                            if (callback) {
                                callback();
                            }
                            that.couponsList.splice(value, 1, that.couponsList[value]);
                        }
                    }
                } else if (data.errMsg) {
                    this.$root.$emit("toast", { msg: data.errMsg })
                } else {
                    this.$root.$emit("toast", { msg: '领取红包失败' })
                }
            })
        },
        getAllCounponsFn (Ary, cb) {
            if (!this.userId) {
                this.$router.push({ path: '/to/login', query: { 'isToPhoneLogin': true } });
                return
            }
            let that = this;
            let tempI = 0;
            let templatIds = [];
            for (let value of Ary) {
                if (value.state == 0) {
                    templatIds.push(value.templateId);
                }
            }
            let params = {
                ids: templatIds
            };
            if (templatIds.length == 0) {
                this.$root.$emit('toast', { msg: `领取失败或不可领取` });
                return;
            }
            let i = 0;
            let time = '';
            if (cb) {
                cb();
            }
            this.$store.dispatch('getAllCounponsFnApi', params).then((data) => {
                if (data.success) {
                    if (data.result.failNum && data.result.successNum) {
                        time = setInterval(() => {
                            // that.templateHide(i);
                            for (let value in that.$refs.coupons) {
                                for (let AryValue in Ary) {
                                    if (Ary[AryValue].promotionId == that.$refs.coupons[value].templates[0].promotionId) {
                                        that.$refs.coupons[value].templateHide(AryValue, Ary[AryValue]);
                                    }
                                }
                            }
                            that.couponsList.forEach((value, index) => {
                                if (Array.isArray(value.couponsProps)) {
                                    value.couponsProps.forEach((couponsItem, couponsIndex) => {
                                        Ary.forEach((AryValue, AryIndex) => {
                                            if (couponsItem.templateId == AryValue.templateId && that.couponsList[index] && that.couponsList[index].couponsProps) {
                                                that.couponsList[index].couponsProps[couponsIndex].state = 7;
                                                if (tempI == 0) {
                                                    tempI = 1
                                                    let couponsList = that.couponsList;
                                                    setTimeout(() => {
                                                        setTimeout(() => {
                                                            that.couponsList = couponsList;
                                                        }, 10)
                                                    }, 1000)
                                                }
                                            }
                                        })
                                    })
                                }
                            })
                            i++;
                            if (i >= Ary.length) {
                                clearInterval(time)
                                i = 0
                            }
                        }, 400);
                        this.$root.$emit('toast', { msg: `成功领取${data.result.successNum}张券，${data.result.failNum}未领取` });
                        setTimeout(() => {
                            this.getPageMsg();
                        }, 1500)
                    } else if (!data.result.failNum && data.result.successNum) {
                        time = setInterval(() => {
                            /*定位是那个页面的劵*/
                            for (let value in that.$refs.coupons) {
                                for (let AryValue in Ary) {
                                    if (Ary[AryValue].promotionId == that.$refs.coupons[value].templates[0].promotionId) {
                                        that.$refs.coupons[value].templateHide(AryValue, Ary[AryValue]);
                                    }
                                }
                            }
                            that.couponsList.forEach((value, index) => {
                                if (Array.isArray(value.couponsProps)) {
                                    value.couponsProps.forEach((couponsItem, couponsIndex) => {
                                        Ary.forEach((AryValue, AryIndex) => {
                                            if (couponsItem.templateId == AryValue.templateId && that.couponsList[index] && that.couponsList[index].couponsProps) {
                                                that.couponsList[index].couponsProps[couponsIndex].state = 7;
                                                if (tempI == 0) {
                                                    tempI = 1
                                                    let couponsList = that.couponsList;
                                                    setTimeout(() => {
                                                        setTimeout(() => {
                                                            that.couponsList = couponsList;
                                                        }, 10)
                                                    }, 1000)
                                                }
                                            }
                                        })
                                    })
                                }
                            })
                            i++;
                            if (i >= Ary.length) {
                                clearInterval(time)
                                i = 0
                            }
                        }, 400);
                        this.$root.$emit('toast', { msg: `成功领取${data.result.successNum}张券` });
                        setTimeout(() => {
                            this.$emit("refresh");
                        }, 1500)
                    } else if (!data.result.successNum && data.result.failNum) {
                        this.$root.$emit('toast', { msg: `领取失败或不可领取` });
                    }
                } else if (data.errMsg) {
                    this.$root.$emit('toast', { msg: data.errMsg });
                } else {
                    this.$root.$emit('toast', "领取失败");
                }
            })
        },
        dealStoreMsg (obj) {
            let that = this;
            let tempList = [];
            let tempStoreMsg = {};
            let promotionInfo = {};
            let promotionFloats = [];
            let redPacketInfo = null
            obj.list.forEach((value, index) => {
                promotionInfo = value.promotionInfo;
                promotionFloats = value.promotionFloats;
                if (JSON.stringify(promotionFloats) != '[]') {
                    promotionFloats.forEach(activityItem => {
                        if (activityItem.packetInfo) {
                            redPacketInfo = activityItem.packetInfo
                        } else {
                            redPacketInfo = null
                        }
                    });
                } else {
                    redPacketInfo = null
                }
                if (!(Array.isArray(promotionFloats) && promotionFloats.length > 0 && promotionFloats[0])) {
                    promotionFloats = [{}]
                }
                let actInfo = promotionFloats[0].actInfo;
                tempStoreMsg = {
                    "promotionId": promotionInfo.promotionId,
                    "mediaType": promotionInfo.mediaType,
                    "mediaContents": promotionInfo.mediaContents,
                    "poster": promotionInfo.poster,
                    "hasWelPacket": !!promotionInfo.packetInfo,
                    "welPacketId": promotionFloats[0].welPacketId,
                    "packetInfo": promotionFloats[0].packetInfo,
                    "promotionChannel": value.promotionChannel,
                    "promotionFloats": value.promotionFloats,
                    "redPacketInfo": redPacketInfo,
                    "welPacketIco": promotionFloats[0].floatIco,
                    "hasTicket": !!promotionFloats[0].templateTickets,
                    // "ticketTemplateIds": promotionInfo.ticketTemplateIds,
                    "templateTickets": promotionFloats[0].templateTickets,
                    "ticketIco": promotionFloats[0].floatIco,
                    "actInfo": actInfo,
                    "hasActivity": !!actInfo,
                    "actType": promotionFloats[0].actType,
                    "actKey": actInfo && actInfo.actKey ? actInfo.actKey : 0,
                    "actTitle": actInfo && actInfo.actTitle ? actInfo.actTitle : '',
                    "actUrl": actInfo && actInfo.actUrl ? actInfo.actUrl : '',
                    "actIco": promotionFloats[0].floatIco,
                    "belongStoreInfo": value.belongStoreInfo,
                    "shareBodyInfo": value.shareBodyInfo,
                }
                tempList.push(tempStoreMsg);
            })
            let tempObj = {
                headerMsg: 'moudule1',
                list: tempList,
            }
            return tempObj
        },
        showRedAlert (booleanMsg = true) {
            if (!this.userId) {
                this.$router.push('/to/login');
                return
            }
            this.isShowAlert = booleanMsg;
            if (booleanMsg) {
                this.$store.state.loadingImg = true;
            }
            setTimeout(() => {
                if (this.$refs.getRedAlert) {
                    this.$refs.getRedAlert.redShow = true;
                }
            }, 20)
        },
        getTemplate (index, obj, cb) {
            //data-couponsId
            let that = this;
            if (!this.userId) {
                this.$router.push({ path: '/to/login', query: { 'isToPhoneLogin': true } });
            } else {
                if (obj.state === 0) {
                    this.$store.dispatch('getTemplateApi', obj.templateId).then((data) => {
                        if (data.success) {
                            if (cb) {
                                cb();
                            }
                            //这里是否需要刷新
                            // this.$emit("refresh");
                            that.couponsList.forEach((value, index) => {
                                if (Array.isArray(value.couponsProps)) {
                                    value.couponsProps.forEach((couponsItem, couponsIndex) => {
                                        if (couponsItem.templateId == obj.templateId) {
                                            that.couponsList[index].couponsProps[couponsIndex].state = 7;
                                            that.couponsList = that.couponsList.splice(index, 1, that.couponsList[index]);
                                            let couponsList = that.couponsList;
                                            setTimeout(() => {
                                                that.couponsList = [];
                                                setTimeout(() => {
                                                    that.couponsList = couponsList;
                                                }, 10)
                                            }, 1000)
                                        }
                                    })
                                }
                            })
                            this.$root.$emit('toast', { msg: '领取成功' })
                        } else if (data.errMsg) {
                            this.$root.$emit('toast', { msg: data.errMsg })
                        } else {
                            this.$root.$emit('toast', { msg: '领取失败' })
                        }
                    })
                } else if (obj.state === 6) {
                    //优惠券详情页面/coupon/template/detail/
                    // this.$router.push({path:'/coupon/template/detail/'+obj.templateId+'/none'})
                } else {
                    this.$root.$emit('toast', { msg: "此券不可领取" });
                }
            }
        },
        suspensionCb (index) {
            let tempObj = this.couponsList[index];
            let tempObj1 = {
                isShow: false
            }
            tempObj = Object.assign({}, tempObj, tempObj1);
            this.couponsList.splice(index, 1, tempObj)
        },
        animationCb (index) {
            let tempObj = this.couponsList[index];
            let tempObj1 = {
                isShow: true
            };
            tempObj = Object.assign({}, tempObj, tempObj1);
            this.couponsList.splice(index, 1, tempObj)
        },
        couponsRedDeal (obj, index) {
            let that = this;
            let tempPromotionList = obj.promotionFloats;
            let couponsProps = [];
            let tempTicketObj = {};
            let tempObjItem = {};
            /*卡券*/
            if (Array.isArray(tempPromotionList) && tempPromotionList.length > 0) {
                tempPromotionList.forEach((promotionItem, promotionIndex) => {
                    if (promotionItem.templateTickets) {
                        for (let value in promotionItem.templateTickets) {
                            let tempObjItem = {
                                templateId: promotionItem.templateTickets[value].templateTicketId,
                                state: promotionItem.templateTickets[value].state,
                                startTime: promotionItem.templateTickets[value].startTime,
                                endTime: promotionItem.templateTickets[value].endTime,
                                ticketType: promotionItem.templateTickets[value].type,
                                scope: promotionItem.templateTickets[value].scope,//使用范围
                                storeIcon: promotionItem.templateTickets[value].logo,
                                promotionId: promotionItem.promotionId,
                                condition: promotionItem.templateTickets[value].condition
                            };
                            couponsProps.splice(value, 1, tempObjItem);
                        }
                        /*红包*/
                    } else if (promotionItem.packetInfo) {
                        let temp = {};
                        // temp.rule = ['邀好友开红包','每成功邀请1次<br/>可领1次红包','进APP提现'];
                        // 普通红包且没有领取的时候只显示领取//是否有可领金额在组件内部处理
                        if (promotionItem.packetInfo.welPacketType == 0) {
                            temp.showGetMoneyBtn = false;//红包提现按钮
                            temp.showGetBtn = true;
                            temp.showShareBtn = false;
                            /*助力红包*/
                        } else if (promotionItem.packetInfo.welPacketType == 1) {
                            /*成长红包*/
                            temp.showGetMoneyBtn = false;//红包提现按钮
                            temp.showGetBtn = true;
                            temp.showShareBtn = false;
                        } else if (promotionItem.packetInfo.welPacketType == 2) {
                            temp.showGetMoneyBtn = false;//红包提现按钮
                            temp.showGetBtn = true;
                            temp.showShareBtn = false;
                        }
                        let tempObjItem = {
                            title: promotionItem.packetInfo.title,
                            redTypeState: promotionItem.packetInfo.welPacketType,
                            rule: [],
                            myPacketInfo: {
                                receivedAmount: promotionItem.packetInfo.receivedAmount,//
                                welPacketId: promotionItem.packetInfo.welPacketId,
                                completeReceived: promotionItem.packetInfo.canReceive,
                                canReceiveAmount: promotionItem.packetInfo.canReceiveAmount,//
                                showReceivedAmount: promotionItem.packetInfo.showReceivedAmount,
                                canReceive: promotionItem.packetInfo.canReceive,
                                lastTimeMillis: promotionItem.packetInfo.lastTimeMillis,//
                                invitedNum: promotionItem.packetInfo.invitedNum,//已经邀约人数
                                waitInvitedNum: promotionItem.packetInfo.waitInvitedNum,//剩余邀请人数
                                packetHelpers: promotionItem.packetInfo.packetHelpers//增长金额
                            },
                        };
                        // couponsProps = tempObjItem;
                        couponsProps.splice(index, 1, tempObjItem);
                    } else if (!(promotionItem.packetInfo || promotionItem.templateTickets)) {
                        couponsProps.splice(index, 1, {});
                    }
                    tempTicketObj = {
                        isShow: false,
                        couponsProps,
                    }
                    that.couponsList.splice(index, 1, tempTicketObj);
                })
            }

        },
        // doAttention (concernType, concernKey, key) {
        //     if (!this.userId) {
        //         this.$router.push('/to/login');
        //         return;
        //     }
        //     let that = this;
        //     let params = {
        //         concernType,
        //         concernKey
        //     }
        //     this.$store.dispatch('doAttentionApi', params).then((data) => {
        //         if (data.success) {
        //             this.storeMsg.list[key].belongStoreInfo.concerned = true;
        //             that.storeMsg.list.splice(key, 1, this.storeMsg.list[key]);
        //         } else if (data.errMsg) {
        //             this.$root.$emit('toast', { msg: data.errMsg })
        //         } else {
        //             this.$root.$emit('toast', { msg: '关注失败' })
        //         }
        //     })
        // },
        isShowHomeTap (boolean) {
            this.$emit('isShowHomeTap', boolean);
        },
        doAppraise (appraiseValue, obj) {
            /*先判断是否登录，然后再判断是否输入了估价的金额*/
            if (!this.userId) {
                this.$router.push({ path: '/to/login' });
                return
            }
            if (appraiseValue != 0 && (!appraiseValue)) {
                this.$root.$emit('toast', { msg: '请输入平均价' });
                return
            }
            /*不为数字*/
            let regVal = /^[0-9\.]+$/ig;
            if (!regVal.test(appraiseValue)) {
                this.$root.$emit('toast', { msg: '价格只能为数字' });
                return
            }
            let params = {
                userId: this.userId,
                actKey: obj.actKey,
                fillerValue: appraiseValue
            }
            this.$store.dispatch('doAppraiseApi', params).then((data) => {
                if (data.success) {
                    // this.interact
                    // let tempObj = {
                    //     show:true,
                    //     averageValue:data.result.averageValue,
                    //     appraiseValue:appraiseValue,
                    //     validNum:data.result.validNum,
                    //     actLimitJoin:data.result.actLimitJoin,
                    // }
                    // this.$refs.fullImgVideoSwiper.updateAppraiseInfo(tempObj);
                    this.$router.push({ path: '/act/finish' })
                } else if (data.errMsg) {
                    this.$root.$emit('toast', { msg: data.errMsg });
                } else {
                    this.$root.$emit('toast', { msg: '估价失败' });
                }
            })

        },
        /*互动中估价 助力*/
        initAppraiseHelp (obj) {
            let userId = 0;
            if (this.$route.query && this.$route.query.identityKey) {
                userId = this.$route.query.identityKey;
            }
            obj = {
                interactId: obj.actKey,                                     //----活动id
                helpUserId: this.currentUser && this.currentUser.userId ? this.currentUser.userId : 0,                         //----帮助力的用户id
                thirdUserId: this.currentThird && this.currentThird.id ? this.currentThird.id : 0,                           //----帮助力的第三方id
                userId: userId,                                              //被帮助者的id
            }
            if (userId && (obj.helpUserId || obj.thirdUserId) && obj.interactId) {
                this.$store.dispatch('initAppraiseHelpApi', obj).then((result) => {
                    if (data.success) {
                        console.log("助力成功")
                    } else if (data.errMsg) {
                        console.log("助力：" + data.errMsg)
                    } else {
                        this.$root.$emit('toast', { msg: '助力失败' });
                    }
                })

            }
            //
        },
        dealShareCollectSpeak (data) {
            let tempObj = {};
            let tempArray = [];
            this.shareCollectSpeak = [];
            data.list.forEach((value, index) => {
                tempObj = {
                    dataInfo: value.dataInfo,
                    isNeedContentShare: false,
                    visitNum: value.dataInfo.visitNum,
                    shareNum: value.dataInfo.shareNum,
                    likeNum: value.dataInfo.likeNum,
                    commentedNum: value.dataInfo.commentedNum,
                    hadLiked: value.hadLiked,
                    mediaId: value.promotionInfo.promotionId,
                    id: value.promotionInfo.promotionId,
                    storeId: value.belongStoreInfo.storeId,
                    latitude: value.belongStoreInfo.latitude,
                    longitude: value.belongStoreInfo.longitude,
                    belongStoreInfo: value.belongStoreInfo,
                    directChannel: value.directChannel,
                };
                tempArray.push(tempObj);
            });
            this.shareCollectSpeak.push(...tempArray);
        },
        getUserMainComment (obj) {
            this.commentPageNum = obj && obj.checkCurPage ? obj.checkCurPage : 1;
            if (obj && obj.mediaId) {
                this.commentKey = obj.mediaId;
            }
            /*commentType 0:多媒体信息 1：店铺实景内容 2：店铺活动 3：店铺商品 4： 商家主页品牌*/
            let params = {
                userId: this.userId,
                commentType: this.commentType,
                commentKey: this.commentKey,
                commentPageNum: this.commentPageNum,
                commentPageSize: this.commentPageSize
            }
            this.$store.dispatch('getUserMainCommentApi', params).then((data) => {
                if (data.success) {
                    let tempObj = { likeType: 0 };// 0-主评论  1-子评论  2-店铺官网媒体   3-店铺商品  4-店铺活动  5-买家秀  6-大师  10-用户多媒体信息
                    if (obj && obj.isLoadingMore) {
                        /*加载更多*/
                        /*把commentListProps替换掉，里面的list push*/
                        let tempList = this.commentListProps.list;
                        tempList.push(...data.list, ...tempObj);
                        data.list = tempList;
                        this.commentListProps = Object.assign({}, this.commentListProps, data);
                    } else {
                        /*获取第一页*/
                        if (this.commentListProps && !this.commentListProps.children) {
                            this.commentListProps = Object.assign({}, this.commentListProps, data, tempObj);
                        }
                    }
                } else if (data.errMsg) {
                    this.$root.$emit({ msg: data.errMsg })
                } else {
                    this.$root.$emit({ msg: "获取页面信息失败" })
                }
            })

        },
        isShowHomeTap (boolean) {
            this.$emit('isShowHomeTap', boolean);
        },
        getSubCommentList (obj) {
            let that = this;
            let params = {
                mainId: obj.mainId,
                pageNum: obj.pageNum,
                pageSize: '5'
            }
            this.$store.dispatch('getSubCommentListApi', params).then((data) => {
                if (data.success) {
                    let tempObj = {
                        children: data,
                    };
                    /*把获取到的子评论加人到主评论对像的children里面去*/
                    for (let value in that.commentListProps.list) {
                        if (that.commentListProps.list[value].id == obj.mainId) {
                            if (obj.isMore) {
                                let tempList = that.commentListProps.list[value].children.list;
                                tempList.push(...data.list);
                                tempObj.children.list = tempList;
                                that.commentListProps.list[value] = Object.assign({}, that.commentListProps.list[value], tempObj);
                                that.commentListProps.list.splice(value, 1, that.commentListProps.list[value]);
                            } else {
                                that.commentListProps.list[value] = Object.assign({}, that.commentListProps.list[value], tempObj);
                                that.commentListProps.list.splice(value, 1, that.commentListProps.list[value]);
                            }
                            break;
                        }
                    }
                } else if (data.errMsg) {
                    this.$root.$emit({ msg: data.errMsg })
                } else {
                    this.$root.$emit({ msg: "获取页面信息失败" })
                }
            })
        },
        doAttention (concernType, concernKey, key, cb) {
            if (!this.userId) {
                this.$router.push('/to/login');
                return;
            }
            let that = this;
            let params = {
                concernType,
                concernKey,
                like: 'do'
            }
            this.$store.dispatch('doAttentionApi', params).then((data) => {
                if (data.success) {
                    for (let value in that.storeMsg.list) {
                        if (that.storeMsg.list[value].belongStoreInfo.storeId == that.storeMsg.list[key].belongStoreInfo.storeId) {
                            that.storeMsg.list[value].belongStoreInfo.concerned = true;
                            that.storeMsg.list.splice(value, 1, this.storeMsg.list[value]);
                        }
                    }
                    if (cb) {
                        cb();
                    }
                    // this.showAlreadyText = true;
                    // setTimeout(()=>{
                    //     this.showAlreadyText = false
                    // },300);
                } else if (data.errMsg) {
                    this.$root.$emit('toast', { msg: data.errMsg })
                } else {
                    this.$root.$emit('toast', { msg: '关注失败' })
                }
            })

        },
        isLike (obj) {
            // likeType
            ///like/user/{userId}/cancel
            // commentType
            let that = this;
            // http://192.168.1.163:7280/nw_api/api/zh/v1.00/like/user/2004/do?likeType=2&&likeKey=3677
            //http://192.168.1.163:7280/nw_api/api/zh/v1.00/like/user/2004/do?likeType=2&&likeKey=31
            let likeType = -1;
            /*子评论点赞*/
            if (obj && Object.keys(obj).includes('mainkey')) {
                if (Object.keys(obj).includes('subKey')) {
                    likeType = 1;
                } else {
                    likeType = 0;
                }
            } else {
                likeType = 4;
            }
            let operation = obj && obj.isLike ? 'do' : 'cancel'
            let params = {
                userId: this.userId,
                likeKey: obj.likeKey,
                likeType,
                operation,
            }
            this.$store.dispatch('isLikeApi', params).then((data) => {
                if (!data.success) {
                    console.log("点赞失败")
                }
            })

        },
        doComment (obj) {
            let paramas = {};
            let that = this;
            if (!obj.content || !obj.content.trim()) {
                this.$root.$emit('toast', { msg: "评论内容不能为空！" })
                return;
            }
            /*主评论*/
            if (obj.belongType < 0) {
                paramas = {
                    data: {
                        commentType: that.commentType,
                        commentKey: that.commentKey,
                        content: obj.content
                    },
                    commentLink: 'main'
                }
            } else {
                /*子评论*/
                paramas = {
                    data: {
                        commentMainId: obj.mainId,
                        commentSubId: parseInt(obj.subId) > 0 ? obj.subId : null,
                        content: obj.content
                    },
                    commentLink: 'sub'
                };
            }
            this.$store.dispatch('doCommentApi', paramas).then((data) => {
                if (data.success) {
                    if (obj.belongType < 0) {
                        this.getUserMainComment();
                        /*评论成功之后页面的操作*/
                        if (obj.belongType < 0) {
                            that.storeMsg.list.forEach((value, index, array) => {
                                if (value.mediaId == that.commentKey) {
                                    that.shareCollectSpeak[index].commentedNum++;
                                    that.shareCollectSpeak.splice(index, 1, that.shareCollectSpeak[index]);
                                }
                            })
                        }
                    } else {
                        /*子评论*/
                        obj.pageNum = 1;
                        that.getSubCommentList(obj);
                    }
                    if (obj && obj.cb) {
                        obj.cb();
                    }
                }
                // else if(data.err){
                //     this.$root.$emit("toast",{msg:'评论失败'})
                // }
            })

        },
    },
    components: {
        "full-img-video-swiper": FullImgVideoSwiper,
        'coupons-v1': () => import('../../components/commonActModel/coupons/couponsV_1/CouponsV_1'),
        "v-share": () => import("../../components/commonComponents/share/Share"),
        "no-data": () => import("../../components/commonActModel/noData/NoData"),

    },
    watch: {
        '$route' (to, from) {
            this.$router.go(0);
        },
    }
}
</script>

<style scoped lang="scss">
@import url($css_root+"css/pages/amusing/amusing.css");

.for-cover {
    height: 100vh;
    position: relative;
}
.amusing /deep/ {
    .fc-header {
        z-index: 1060 !important;
    }
}
.for-cover /deep/ {
    .couponsV_1 {
        bottom: 0.6rem;
        position: absolute;
    }

    .swiper-pagination {
        z-index: 20;
        opacity: 1;
        position: absolute;
    }

    .fc-suspension {
        position: absolute;
    }
    .look-index-mood {
        position: static;
        padding: 0;
    }
    .no-wcomment {
        z-index: 1;
        background-image: linear-gradient(
            rgba(0, 0, 0, 0.3) 0%,
            rgba(0, 0, 0, 0) 20%,
            rgba(0, 0, 0, 0) 80%,
            rgba(0, 0, 0, 0.3) 100%
        );
    }
    .fc-userheader-des .displayBlock {
        max-width: 1.5rem;
    }
}

.animated.zoomOut {
    -webkit-animation-duration: 300ms;
    animation-duration: 300ms; // 动画执行时间
}

.suspension-leave {
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    -o-transition: all 1s;
    transition: all 1s;
    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -ms-transform: scale(0);
    -o-transform: scale(0);
    transform: scale(0);
}

.amusing-top-icon {
    height: 0.21rem;
    width: 0.21rem;
    margin-left: 0.1rem;
}

.fc-wtop-icon {
    position: absolute;
    right: 0.2rem;
    top: 0.25rem;
    left: auto;
    bottom: auto;
}
</style>